<!--
 * @Description:  
 * @Version: 1.0
 * @Autor: gaoluo
 * @Date: 2022-04-28 15:47:51
 * @LastEditors: gaoluo
 * @LastEditTime: 2022-04-28 17:36:44
 * @FilePath: /vue3.0-vite-ts-xiaotuxian/src/components/test.vue
-->

<template>
  <div>
    <label for="">checkbox:</label>
    <input type="checkbox" value="xiaoming1" :checked="checkboxName.includes('xiaoming1')"
      @change="onHanleChange($event)">
    <label for="">checkbox:</label>
    <input type="checkbox" value="xiaoming" :checked="checkboxName.includes('xiaoming')"
      @change="onHanleChange($event)">
  </div>
  n1:<input type="checkbox" name="de1" id="" value="n1">
  n2:<input type="checkbox" name="de1" id="" value="n2">
</template>

<script setup lang="ts">
import { ref } from '@vue/reactivity';

const onHanleChange = (e: Event): void => {
  const target = e.target as HTMLInputElement;
  target.checked ?
    checkboxName.value.push(target.value)
    : checkboxName.value.splice(checkboxName.value.indexOf(target.value), 1)
  console.log(
    checkboxName.value
  )
}

const checkboxName = ref<string[]>([]);
</script>

<style scoped>
</style>
